<template>
  <view>
    <view class="">
      <uni-list :border="true">
        <uni-list-chat :title="stateTitle" avatar="https://s2.loli.net/2022/05/08/V9KDpJoE3FlyT2S.png" :note='content' :time="postMessage.gmtModified" badge-positon="left" :badgeText="num" clickable="true" :to="'../../subpkg/postitem/postitem?id=' + serialNumber[0]" @click="gotoPostItem"></uni-list-chat>
      </uni-list>
    </view>
  </view>
</template>

<script>
  export default {
    name:"user-message",
    props: {
      postMessage: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        title: '',
        content: '',
        stateTitle: '',
        num: this.postMessage.isRead === 0 ? 'dot' : '',
        serialNumber: this.postMessage.info.match(/\d+/g),
        stateStr: this.postMessage.info.replace(/\d+/g,''),
      };
    },
    methods: {
      getTitle() {
          if(this.stateStr === '发布任务') {
            this.stateTitle = '发布成功'
            this.content = '任务\"' + this.postMessage.taskTitle + '\"发布成功，点击查看详情' 
          } else if(this.stateStr === 'task过期') {
            this.stateTitle = '组队失败'
            this.content = '任务\"' + this.postMessage.taskTitle + '\"组队失败，点击查看详情' 
          } else if(this.stateStr.indexOf('加入组队成功') !== -1) {
            this.stateTitle = this.stateStr
            this.content = '任务\"' + this.postMessage.taskTitle + '\"组队成功，点击查看详情' 
          } else if(this.stateStr.indexOf('您已加入组队成功') !== -1) {
            this.stateTitle = '加入组队成功'
            this.content = '任务\"' + this.postMessage.taskTitle + '\"组队成功，点击查看详情' 
          } else {
            this.stateTitle = '组队成功' 
             this.content = '任务\"' + this.postMessage.taskTitle + '\"组队成功，点击查看详情' 
          }
      },
      radioClickHandler() {
        this.$emit('radio-change',{
          isSelected: !this.postItem.isSelected,
          serialNumber: this.postItem.serialNumber
        })
      },
      async gotoPostItem() {
        const {data:res} = await uni.$http.post('/api/inbox/set/InfoIsRead/' + this.postMessage.id).catch(err => uni.$showMsg('网络错误！'))
        if(res.code !== 200) return uni.$showMsg()
      }
    },
    mounted() {
      this.getTitle()
    }
  }
</script>

<style lang="scss">

</style>
